Imports Microsoft.VisualBasic
Imports System.Data
Imports FirebirdSql.Data
Imports FirebirdSql.Data.FirebirdClient
Imports FirebirdSql.Data.FirebirdClient.FbTransaction

Public Class _DataBase

#Region "Objetos Privados"

    Private montaConnectStringFB As String = "User=SYSDBA;Password=CP0nt0062013; " & _
                                             "Database=" & My.Settings.DataBase & ";" & _
                                             "DataSource= " & My.Settings.DataSource & ";" & _
                                             "Port=3050;" & _
                                             "Dialect=3;" & _
                                             "Charset=NONE;" & _
                                             "Role=;" & _
                                             "Connection lifetime=15;" & _
                                             "Pooling=true;" & _
                                             "MinPoolSize=0;" & _
                                             "MaxPoolSize=50;Packet Size=8192;ServerType=0"

    Private f_conn As New FbConnection(montaConnectStringFB)

    Private f_dta As New FbDataAdapter
    Private f_cmd As New FbCommand
    Private f_cmd2 As New FbCommand
    Private f_dr As FbDataReader
    Private f_dsItens As New DataSet
    Private f_msgRetorno As String


#End Region

#Region "Propriedades Publicas"

    Protected Property dsItens() As DataSet
        Get
            Return f_dsItens
        End Get
        Set(ByVal value As DataSet)
            f_dsItens = value
        End Set
    End Property

    Protected Property cmd2() As FbCommand
        Get
            Return f_cmd2
        End Get
        Set(ByVal value As FbCommand)
            f_cmd2 = value
        End Set
    End Property

    ''' <summary>
    ''' Objeto de conexao com banco de dados
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Protected Property conn() As FbConnection
        Get
            Return f_conn
        End Get
        Set(ByVal value As FbConnection)
            f_conn = value
        End Set
    End Property

    ''' <summary>
    ''' Propriedade para comando sql - sqlCommand
    ''' </summary>
    ''' <value></value>
    ''' <returns>retorno definido pelo metodo que o implementa</returns>
    ''' <remarks></remarks>

    Shadows Property cmd() As FbCommand
        Get
            Return f_cmd
        End Get
        Set(ByVal value As FbCommand)
            f_cmd = value
        End Set
    End Property

    ''' <summary>
    ''' Propriedade sqlDataAdapter
    ''' </summary>
    ''' <value></value>
    ''' <returns> retorna DataAdpter</returns>
    ''' <remarks></remarks>

    Protected Property dta() As FbDataAdapter
        Get
            Return f_dta
        End Get
        Set(ByVal value As FbDataAdapter)
            f_dta = value
        End Set
    End Property

    Protected Property dr() As FbDataReader
        Get
            Return f_dr
        End Get
        Set(ByVal value As FbDataReader)
            f_dr = value
        End Set
    End Property

    Public Property msgRetorno() As String
        Get
            Return f_msgRetorno
        End Get
        Set(ByVal value As String)
            f_msgRetorno = value
        End Set
    End Property

#End Region

#Region "Metodos publicos"

    Protected Function retornaDataSet(ByVal strSQL As FbCommand) As DataSet

        Me.dta = New FbDataAdapter
        dta.SelectCommand = strSQL
        retornaDataSet = New DataSet
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = strSQL.CommandText
        cmd.Connection = conn
        dta.Fill(retornaDataSet, "dataSet")

        Return retornaDataSet

    End Function

    Protected Function retornaDataReader(ByVal strSQL As FbCommand) As FbDataReader

        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = strSQL.CommandText
        cmd.Connection = conn
        dr = cmd.ExecuteReader()

        Return dr

    End Function

    Protected Function execSQL(ByVal strSQL As FbCommand) As Integer

        strSQL.CommandText = strSQL.CommandText
        strSQL.CommandType = CommandType.StoredProcedure
        strSQL.Connection = conn

        Return cmd.ExecuteScalar()

    End Function
    Protected Sub execSQLSemRetorno(ByVal strSQL As FbCommand)

        strSQL.CommandText = strSQL.CommandText
        strSQL.CommandType = CommandType.StoredProcedure
        strSQL.Connection = conn
        cmd.ExecuteNonQuery()

    End Sub

    Protected Sub conectaDb()
        Me.conn.Open()
    End Sub

    Protected Sub desconectaDb()

        Me.conn.Close()

    End Sub

#End Region

End Class
